package com.jhyj.shop;

import com.jhyj.shop.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;

import utils.SpUtils;

/**
 * 商城欢迎界面
 * author:wbin
 *
 */
public class SplashActivity extends Activity {
	
	private ImageView iv_splash;
	private ScaleAnimation scaleAnimation;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_splash);
		
		iv_splash = (ImageView) findViewById(R.id.iv_splash);
		
		startAnimation();
	}

	/**
	 * 设置闪屏页面的动画
	 */
	private void startAnimation() {
		scaleAnimation = new ScaleAnimation(1, 1.1f, 1, 1.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		scaleAnimation.setDuration(1500);
		scaleAnimation.setFillAfter(true);
		iv_splash.startAnimation(scaleAnimation);
		
		scaleAnimation.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				intoActivity();
			}
		});
	}
	
	/**
	 * 判断是否第一次进入，第一次进入则进入向导页面，否则进入主页面
	 */
	private void intoActivity() {
		boolean firststart = new SpUtils(this).get(SpUtils.FIRST_START, true);
		if(firststart) {
			startActivity(new Intent(this, GuideActivity.class));
		} else {
			startActivity(new Intent(this, MainActivity.class));
		}
		finish();
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
}
